<% var obj = {pageTitle:"宿管列表"} %>
{{include "../header.html" obj}}
<div class=" container">
    {{include "../pageHeader.html" obj}}
    <div class=" btn-group pull-right" style="margin-bottom:5px;">
        <button type="button" class=" btn btn-danger" id="delAll">
            <span class=" glyphicon glyphicon-trash"></span>
            批量删除
        </button>
    </div>
    <form action="/dormadmin/queryList" method="GET" class=" form-inline" style="margin:5px 0px;">
        <div class=" form-group">
            <label for="" class=" control-label">编号</label>
            <span><input type="text" class=" form-control" name="da_id"></span>
        </div>
        <div class=" form-group">
            <label for="" class=" control-label">姓名</label>
            <span><input type="text" class=" form-control" name="da_name"></span>
        </div>
        <div class=" form-group">
            <label for="" class=" control-label">性别</label>
            <select name="da_sex" id="" class=" form-control">
                <option value="">--请选择--</option>
                <option value="男">男</option>
                <option value="女">女</option>
            </select>
        </div>
        <div class=" form-group">
            <button type="submit" class=" btn btn-primary btn-submit-loading">查询</button>
        </div>
    </form>
    <div class=" table-responsive">
        <table class=" table table-striped table-hover table-bordered">
            <tr>
                <td>
                    <label for="#ckAll">
                        <input type="checkbox" id="ckAll" class=" ckAll">全选
                    </label>
                </td>
                <td>编号</td>
                <td>姓名</td>
                <td>性别</td>
                <td>电话</td>
                <td>操作</td>
            </tr>
            {{each result item index}}
            <tr>
                <td>
                    <input type="checkbox" name="ck" value="{{item.da_id}}">
                </td>
                <td>{{item.da_id}}</td>
                <td>{{item.da_name}}</td>
                <td>{{item.da_sex}}</td>
                <td>{{item.da_tel}}</td>
                <td>
                    <label for="" id="edit" class=" label btn-warning" data-toggle="modal" data-target="#modal1">编辑</label>
                    <label for="" id="delete" data-da_id="{{item.da_id}}" class=" label btn-danger">删除</label>
                </td>
            </tr>
            {{/each}}
        </table>
    </div>
</div>
<div class=" modal fade" id="modal1">
    <div class=" modal-dialog">
        <div class=" modal-content">
            <div class=" modal-header">
                <span class=" close" data-dismiss="modal">&times;</span>
                <h2 class=" text-center text-primary">编辑</h2>
            </div>
            <form method="POST" action="/dormadmin/upDormadmin" class=" form-horizontal" enctype="application/x-www-form-urlencoded">
                <div class=" modal-body">
                    {{each dormadin_info item index}}
                    <% var obj = {item} %>
                    {{if item[1]=="性别"}}
                    {{include "../bs_views/form_group_select.html" obj}}
                    {{else}}
                    {{include "../bs_views/form_group_input.html" obj}}
                    {{/if}}
                    {{/each}}
                </div>
                <div class=" modal-footer">
                    <div class=" form-group">
                        <div class=" col-sm-7 col-sm-offset-3">
                            <button type="submit" class=" btn btn-primary btn-submit-loading">保存</button>
                            <button type="reset" class=" btn btn-warning" data-dismiss="modal">关闭</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    $(function () {
        $(".table").on("click", "label", function (event) {
            event = window.event || event;
            if (event.target.id == 'edit') {
                var arr = [];
                $(event.target.parentElement).prevAll().not(":last").each(function (index, element) {
                    // element == this
                    arr.unshift($(this).text());
                });
                $("#modal1 .form-control").each(function (index, element) {
                    // element == this
                    $(this).val(arr[index]);
                });
            }
            if (event.target.id == "delete") {
                let da_id = $(this).data("da_id");
                if (confirm("确认操作！")) {
                    $.get("/dormadmin/delDormadmin?da_id=" + da_id,
                        function (data, textStatus, jqXHR) {
                            if (data.status == "success") {
                                alert(data.msg);
                                location.reload();
                            }
                            else {
                                alert(data.msg);
                            }
                        }
                    );
                }
            }
        });
        $(".form-control").inputTips();
        $("#delAll").click(function (e) {
            if ($("[name='ck']:checked").length > 0) {
                if (confirm("你确定要删除所有选中项吗！")) {
                    let da_idArr = [];
                    $("[name='ck']:checked").each(function (index, element) {
                        // element == this
                        da_idArr.push($(this).val());
                    });
                    console.log(da_idArr);
                    $.get("/dormadmin/delAllDormadmin?da_idArr=" + da_idArr.join("-"),
                        function (data, textStatus, jqXHR) {
                            if (data.status == "success") {
                                alert(data.msg);
                                location.reload();
                            }
                            else {
                                alert(data.msg);
                            }
                        }
                    );
                }
            }
        });
        $("#modal1 input:first").prop("readonly", true);
    })
</script>
{{include "../footer.html"}}